home *** CD-ROM | disk | FTP | other *** search
/ Aminet 24 / Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso / Aminet / dev / c / AmiVoGL_MDEV.lha / examples / fshapes.for < prev    next >
Text File  |  1991-06-03  |  4KB  |  158 lines

  1.     program fshapes
  2.  
  3. $INCLUDE: 'fvogl.h'
  4. $INCLUDE: 'fvodevic.h'
  5.  
  6. c
  7. c This program shows some of the simple primitives.
  8. c
  9.     integer edgel
  10.     integer *2 val, vminx, vmaxx, vminy, vmaxy
  11. c
  12. c open a window (or the screen on some devices)
  13. c
  14.     call prefsi(512, 600)
  15.     call winope('shapes', 6)
  16.     call unqdev(INPUTC)
  17.  
  18. c the two lines below clear the screen to white if we have
  19. c colours, on a monochrome device color is ignored so the
  20. c screen will be cleared to its background color, normally black.
  21. c
  22.     call color(BLACK)
  23.     call clear()
  24.  
  25. c
  26. c set the screen to be 2.0 units wide and 2.0 units wide, with
  27. c the drawable coordinates going from -1.0 to 1.0.
  28. c
  29.     call ortho2(-1.0, 1.0, -1.0, 1.0)
  30.  
  31.     call color(MAGENT)
  32.  
  33. c
  34. c okay, so we want to draw in the range -1 to 1, but we
  35. c only want to draw in the top lefthand corner of the
  36. c screen. The call to viewpo allows us to do this. As
  37. c viewpo always takes screen coordinates, we need to
  38. c call getviewpo to found out how big our screen is
  39. c at the moment. We use the values returned from getviewpo
  40. c calculate the positions for our new viewpo. We note
  41. c that on an Iris (0,0) is the bottom left pixel.
  42. c
  43.     call getvie(vminx, vmaxx, vminy, vmaxy)
  44.  
  45.     maxx = vmaxx
  46.     minx = vminx
  47.     maxy = vmaxy
  48.     miny = vminy
  49.  
  50.     call viewpo(minx, (maxx - minx) / 2, (maxy - miny) / 2, maxy)
  51.  
  52. c
  53. c  write out a heading 
  54. c
  55.     call cmov2(-0.9, -0.5)
  56.     call charst('rect', 4)
  57.  
  58. c
  59. c draw a rectangle around the points (-0.2, -0.2), (-0.2, 0.2),
  60. c (0.3, 0.2), and (0.3, -0.2).
  61. c
  62.     call rect(-0.2, -0.2, 0.3, 0.2)
  63.  
  64.     call color(BLUE)
  65.  
  66. c
  67. c now we want to draw in the top right corner of the screen,
  68. c and we want to draw a circular circle so we must make sure
  69. c our viewpo is square (if it isn't we'll get an ellipse),
  70. c so we calculate the shortest edge and set up a viewpo which
  71. c is in the top right region of the screen, but doesn't necessarilly
  72. c occupy all the top right corner.
  73. c
  74. c find smallest edge 
  75. c
  76.     if (maxx - minx .gt. maxy - miny) then
  77.         edgel = (maxy - miny) / 2
  78.     else 
  79.         edgel = (maxx - minx) / 2
  80.     end if
  81.  
  82. c
  83. c create a square viewpo - otherwise the circle will look
  84. c like an ellipse.
  85. c
  86.  
  87.     call viewpo((maxx - minx) / 2, (maxx - minx) / 2 + edgel,
  88.      +           (maxy - miny) / 2, (maxy - miny) / 2 + edgel)
  89.  
  90.     call cmov2(-0.9, -0.5)
  91.     call charst('circle', 6)
  92.  
  93. c
  94. c draw a circle of radius 0.4 around the point (0.0, 0.0)
  95. c
  96.     call circ(0.0, 0.0, 0.4)
  97.  
  98.     call color(GREEN)
  99.  
  100. c
  101. c bottom left hand corner.
  102. c
  103.     call viewpo(minx, (maxx - minx) / 2,
  104.      +                miny, (maxy - miny) / 2)
  105.  
  106.     call cmov2(-0.9, -0.5)
  107.     call charst('ellipse', 7)
  108.  
  109. c
  110. c To draw an ellipse we change the aspect ratio so it is no longer
  111. c 1 and call circ. In this case we use ortho2 to make the square
  112. c viewpo appear to be higher than it is wide. Alternatively you
  113. c could use arc to construct one.
  114. c
  115. c The call to pushmatrix saves the current viewing transformation.
  116. c After the ortho2 has been done, we restore the current viewing
  117. c transformation with a call to popmatrix. (Otherwise everything
  118. c after the call to ortho would come out looking squashed as the
  119. c world aspect ratio is no longer 1).
  120. c
  121.     call pushma
  122.         call ortho2(-1.0, 1.0, -1.0, 2.0)
  123.         call circ(0.0, 0.5, 0.4)
  124.     call popmat
  125.  
  126.     call color(RED)
  127.  
  128. c
  129. c bottom right hand corner
  130. c
  131.     call viewpo((maxx - minx) / 2, maxx,
  132.      +                 miny, (maxy - miny) / 2)
  133.  
  134.     call cmov2(-0.9, -0.5)
  135.     call charst('arc', 3)
  136.  
  137. c
  138. c draw an arc centered at (0.0, 0.0), radius of 0.4. 0.0 is the start
  139. c angle and 90.0 is the end angle of the arc being drawn. So this
  140. c draws a quarter circle - unless our viewpo isn't square.
  141. c
  142.     call arc(0.0, 0.0, 0.4, 0, 900)
  143.  
  144. c
  145. c we want to stop after a keyboard event
  146. c
  147.     call qdevic(KEYBD)
  148.  
  149. c
  150. c wait for the event
  151. c
  152.     idum = qread(val)
  153.  
  154.     call gexit
  155.  
  156.     end
  157.